package com.app.rest.test;

import java.sql.SQLException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.app.rest.object.User;
import com.app.rest.database.*;;

@Path("/auth/{name}")
public class AuthenticationReq {
	
	  @GET
	  @Produces(MediaType.TEXT_HTML)
	  public String sayHello(@PathParam("name") String name) {
		/**
		 * TODO password encode
		 */
		String responseAuth = "";
		User userCheck = new User(name, "test123");
		String authResult = "";
		try {
			authResult = DBmanager.getAuthentication(userCheck);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(authResult.equalsIgnoreCase("")){
			responseAuth = "<p> User "+ name + " is not registered. </p>";
		} else if(authResult.equalsIgnoreCase(name)) {
			responseAuth = "<p> User "+ name + " is in the system. </p>";
		}
		
	    return responseAuth+"<p> end</p>";
	  }
	  
}
